import { getUserSession } from 'services/EnterpriseCertificationListService'
export default {
    namespaces: 'EnterpriseCertificationListModel',
    state: {
        Session: '',
        // url: '',
        enterType: ''
    },
    reducers: {
        setQuery(state, { payload }) {
            return {
                ...state,
                Session: payload.Session,
                // url: payload.url,
                enterType: payload.enterType
            }
        }
    },
    effects: {
        *getUserWsid({ payload, callback }, { call, put }) {
            let res = yield call(getUserSession, payload)
            let { code } = res
            let reg = new RegExp(/0000$/, 'i')
            //如果请求成功
            if(reg.test(code)) {
                let { session: { userWsid } } = res
                yield callback('success', userWsid)
            } else {
                yield callback('error')
            }
        }
    },
    subscriptions: {
        getQuery({ dispatch, history }) {
            history.listen(location => {
                if(location.pathname === '/EnterpriseCertificationList') {
                    let { Session, enterType } = location.query
                    dispatch({
                        type: 'setQuery',
                        payload: {
                            Session,
                            enterType
                        }
                    })
                }
            })
        }
    }
}
